package com.wephone.Student.ui;

import java.io.File;
import java.io.FileNotFoundException;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.loopj.android.http.RequestParams;
import com.wephone.Student.R;
import com.wephone.Student.bean.BaseResponse;
import com.wephone.Student.network.HttpClient;
import com.wephone.Student.network.MyResponseHandler;
import com.wephone.Student.util.Constants;
import com.wephone.Student.util.Util;

public class CreateLiuxuequanActivity extends BaseActivity {
	private EditText contentEdit;
	private File photoSavedFile1 = null;
	private String photoSavedName1 = null;
	private File photoSavedFile2 = null;
	private String photoSavedName2 = null;
	private File photoSavedFile3 = null;
	private String photoSavedName3 = null;
	private File photoSavedFile4 = null;
	private String photoSavedName4 = null;
	private File photoSavedFile5 = null;
	private String photoSavedName5 = null;
	private File photoSavedFile6 = null;
	private String photoSavedName6 = null;
	private File photoSavedFile7 = null;
	private String photoSavedName7 = null;
	private File photoSavedFile8 = null;
	private String photoSavedName8 = null;
	private File photoSavedFile9 = null;
	private String photoSavedName9 = null;
	private ImageView addPicImage1;
	private ImageView addPicImage2;
	private ImageView addPicImage3;
	private ImageView addPicImage4;
	private ImageView addPicImage5;
	private ImageView addPicImage6;
	private ImageView addPicImage7;
	private ImageView addPicImage8;
	private ImageView addPicImage9;
	private boolean hasPhotoUpload = false;
	private TextView maxQuestionText;
	private int picIdx=0;
	private boolean isUploading = false;
	
	private MyResponseHandler getHandler(){
		MyResponseHandler handler = new MyResponseHandler(CreateLiuxuequanActivity.this,BaseResponse.class){
			@Override
			public void onSuccess(String result) {
				super.onSuccess(result);
				
				isUploading = false;
				if(getDataSuccess){
					Toast.makeText(getApplicationContext(), "山楂圈发布成功", Toast.LENGTH_LONG).show();
					setResult(11);
					finish();
				}
			}

			@Override
			public void onFailure(Throwable arg0, String result) {
				super.onFailure(arg0, result);
				isUploading = false;
			}
			
		};
		return handler;
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if(requestCode==1){
//			System.out.println("-------picIdx---------"+picIdx);
			if(picIdx==0){
				if(photoSavedFile1!=null && photoSavedFile1.exists()){
					hasPhotoUpload = true;
					Bitmap bitmap = Util.getBitmap(getApplicationContext(),photoSavedFile1.getPath(),200);
					addPicImage1.setImageBitmap(bitmap);
					addPicImage1.setVisibility(View.VISIBLE);
					addPicImage1.setOnClickListener(new View.OnClickListener() {
						@Override
						public void onClick(View arg0) {
							Bundle bundle = new Bundle();
							bundle.putString("imgUrl", "file://"+photoSavedFile1.getPath());
							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
						}
					});
	       		 	Util.saveMyBitmap(bitmap,photoSavedName1,getApplicationContext());
	       		 	picIdx++;
				}else if(data!=null){
					Bundle bundle = data.getExtras();
					if(bundle!=null){
						Bitmap tmpbitmap = (Bitmap)bundle.get("data");
						if(tmpbitmap!=null){
							hasPhotoUpload = true;
							addPicImage1.setImageBitmap(tmpbitmap);
							addPicImage1.setVisibility(View.VISIBLE);
							addPicImage1.setOnClickListener(new View.OnClickListener() {
								@Override
								public void onClick(View arg0) {
									Bundle bundle = new Bundle();
									bundle.putString("imgUrl", "file://"+photoSavedFile1.getPath());
									startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
								}
							});
			       		 	Util.saveMyBitmap(tmpbitmap,photoSavedName1,getApplicationContext());
			        		picIdx++;
						}
					}
				}
    		}else if(picIdx==1){
    			if(photoSavedFile2!=null && photoSavedFile2.exists()){
        			hasPhotoUpload = true;
        			Bitmap bitmap = Util.getBitmap(getApplicationContext(),photoSavedFile2.getPath(),200);
        			addPicImage2.setImageBitmap(bitmap);
        			addPicImage2.setVisibility(View.VISIBLE);
        			addPicImage2.setOnClickListener(new View.OnClickListener() {
						@Override
						public void onClick(View arg0) {
							Bundle bundle = new Bundle();
							bundle.putString("imgUrl", "file://"+photoSavedFile2.getPath());
							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
						}
					});
           		 	Util.saveMyBitmap(bitmap,photoSavedName2,getApplicationContext());
           		 	picIdx++;
    			}else if(data!=null){
    				Bundle bundle = data.getExtras();
    				if(bundle!=null){
    					Bitmap tmpbitmap = (Bitmap)bundle.get("data");
    					if(tmpbitmap!=null){
    						hasPhotoUpload = true;
    						addPicImage2.setImageBitmap(tmpbitmap);
    						addPicImage2.setVisibility(View.VISIBLE);
    						addPicImage2.setOnClickListener(new View.OnClickListener() {
    							@Override
    							public void onClick(View arg0) {
    								Bundle bundle = new Bundle();
    								bundle.putString("imgUrl", "file://"+photoSavedFile2.getPath());
    								startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
    							}
    						});
		           		 	Util.saveMyBitmap(tmpbitmap,photoSavedName2,getApplicationContext());
    		        		picIdx++;
    					}
    				}
    			}
    		}else if(picIdx==2){
    			if(photoSavedFile3!=null && photoSavedFile3.exists()){
        			hasPhotoUpload = true;
        			Bitmap bitmap = Util.getBitmap(getApplicationContext(),photoSavedFile3.getPath(),200);
        			addPicImage3.setImageBitmap(bitmap);
        			addPicImage3.setVisibility(View.VISIBLE);
        			addPicImage3.setOnClickListener(new View.OnClickListener() {
						@Override
						public void onClick(View arg0) {
							Bundle bundle = new Bundle();
							bundle.putString("imgUrl", "file://"+photoSavedFile3.getPath());
							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
						}
					});
           		 	Util.saveMyBitmap(bitmap,photoSavedName3,getApplicationContext());
           		 	picIdx++;
    			}else if(data!=null){
    				Bundle bundle = data.getExtras();
    				if(bundle!=null){
    					Bitmap tmpbitmap = (Bitmap)bundle.get("data");
    					if(tmpbitmap!=null){
    						hasPhotoUpload = true;
    						addPicImage3.setImageBitmap(tmpbitmap);
    						addPicImage3.setVisibility(View.VISIBLE);
    						addPicImage3.setOnClickListener(new View.OnClickListener() {
    							@Override
    							public void onClick(View arg0) {
    								Bundle bundle = new Bundle();
    								bundle.putString("imgUrl", "file://"+photoSavedFile3.getPath());
    								startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
    							}
    						});
		           		 	Util.saveMyBitmap(tmpbitmap,photoSavedName3,getApplicationContext());
    		        		picIdx++;
    					}
    				}
    			}
    		}else if(picIdx==3){
    			if(photoSavedFile4!=null && photoSavedFile4.exists()){
        			hasPhotoUpload = true;
        			Bitmap bitmap = Util.getBitmap(getApplicationContext(),photoSavedFile4.getPath(),200);
        			addPicImage4.setImageBitmap(bitmap);
        			addPicImage4.setVisibility(View.VISIBLE);
        			addPicImage4.setOnClickListener(new View.OnClickListener() {
						@Override
						public void onClick(View arg0) {
							Bundle bundle = new Bundle();
							bundle.putString("imgUrl", "file://"+photoSavedFile4.getPath());
							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
						}
					});
           		 	Util.saveMyBitmap(bitmap,photoSavedName4,getApplicationContext());
           		 	picIdx++;
    			}else if(data!=null){
    				Bundle bundle = data.getExtras();
    				if(bundle!=null){
    					Bitmap tmpbitmap = (Bitmap)bundle.get("data");
    					if(tmpbitmap!=null){
    						hasPhotoUpload = true;
    						addPicImage4.setImageBitmap(tmpbitmap);
    						addPicImage4.setVisibility(View.VISIBLE);
    						addPicImage4.setOnClickListener(new View.OnClickListener() {
    							@Override
    							public void onClick(View arg0) {
    								Bundle bundle = new Bundle();
    								bundle.putString("imgUrl", "file://"+photoSavedFile4.getPath());
    								startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
    							}
    						});
		           		 	Util.saveMyBitmap(tmpbitmap,photoSavedName4,getApplicationContext());
    		        		picIdx++;
    					}
    				}
    			}
    		}else if(picIdx==4){
    			if(photoSavedFile5!=null && photoSavedFile5.exists()){
        			hasPhotoUpload = true;
        			Bitmap bitmap = Util.getBitmap(getApplicationContext(),photoSavedFile5.getPath(),200);
        			addPicImage5.setImageBitmap(bitmap);
        			addPicImage5.setVisibility(View.VISIBLE);
        			addPicImage5.setOnClickListener(new View.OnClickListener() {
						@Override
						public void onClick(View arg0) {
							Bundle bundle = new Bundle();
							bundle.putString("imgUrl", "file://"+photoSavedFile5.getPath());
							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
						}
					});
           		 	Util.saveMyBitmap(bitmap,photoSavedName5,getApplicationContext());
           		 	picIdx++;
    			}else if(data!=null){
    				Bundle bundle = data.getExtras();
    				if(bundle!=null){
    					Bitmap tmpbitmap = (Bitmap)bundle.get("data");
    					if(tmpbitmap!=null){
    						hasPhotoUpload = true;
    						addPicImage5.setImageBitmap(tmpbitmap);
    						addPicImage5.setVisibility(View.VISIBLE);
    						addPicImage5.setOnClickListener(new View.OnClickListener() {
    							@Override
    							public void onClick(View arg0) {
    								Bundle bundle = new Bundle();
    								bundle.putString("imgUrl", "file://"+photoSavedFile5.getPath());
    								startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
    							}
    						});
		           		 	Util.saveMyBitmap(tmpbitmap,photoSavedName5,getApplicationContext());
    		        		picIdx++;
    					}
    				}
    			}
    		}else if(picIdx==5){
    			if(photoSavedFile6!=null && photoSavedFile6.exists()){
        			hasPhotoUpload = true;
        			Bitmap bitmap = Util.getBitmap(getApplicationContext(),photoSavedFile6.getPath(),200);
        			addPicImage6.setImageBitmap(bitmap);
        			addPicImage6.setVisibility(View.VISIBLE);
        			addPicImage6.setOnClickListener(new View.OnClickListener() {
						@Override
						public void onClick(View arg0) {
							Bundle bundle = new Bundle();
							bundle.putString("imgUrl", "file://"+photoSavedFile6.getPath());
							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
						}
					});
           		 	Util.saveMyBitmap(bitmap,photoSavedName6,getApplicationContext());
           		 	picIdx++;
    			}else if(data!=null){
    				Bundle bundle = data.getExtras();
    				if(bundle!=null){
    					Bitmap tmpbitmap = (Bitmap)bundle.get("data");
    					if(tmpbitmap!=null){
    						hasPhotoUpload = true;
    						addPicImage6.setImageBitmap(tmpbitmap);
    						addPicImage6.setVisibility(View.VISIBLE);
    						addPicImage6.setOnClickListener(new View.OnClickListener() {
    							@Override
    							public void onClick(View arg0) {
    								Bundle bundle = new Bundle();
    								bundle.putString("imgUrl", "file://"+photoSavedFile6.getPath());
    								startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
    							}
    						});
		           		 	Util.saveMyBitmap(tmpbitmap,photoSavedName6,getApplicationContext());
    		        		picIdx++;
    					}
    				}
    			}
    		}else if(picIdx==6){
    			if(photoSavedFile7!=null && photoSavedFile7.exists()){
        			hasPhotoUpload = true;
        			Bitmap bitmap = Util.getBitmap(getApplicationContext(),photoSavedFile7.getPath(),200);
        			addPicImage7.setImageBitmap(bitmap);
        			addPicImage7.setVisibility(View.VISIBLE);
        			addPicImage7.setOnClickListener(new View.OnClickListener() {
						@Override
						public void onClick(View arg0) {
							Bundle bundle = new Bundle();
							bundle.putString("imgUrl", "file://"+photoSavedFile7.getPath());
							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
						}
					});
           		 	Util.saveMyBitmap(bitmap,photoSavedName7,getApplicationContext());
           		 	picIdx++;
    			}else if(data!=null){
    				Bundle bundle = data.getExtras();
    				if(bundle!=null){
    					Bitmap tmpbitmap = (Bitmap)bundle.get("data");
    					if(tmpbitmap!=null){
    						hasPhotoUpload = true;
    						addPicImage7.setImageBitmap(tmpbitmap);
    						addPicImage7.setVisibility(View.VISIBLE);
    						addPicImage7.setOnClickListener(new View.OnClickListener() {
    							@Override
    							public void onClick(View arg0) {
    								Bundle bundle = new Bundle();
    								bundle.putString("imgUrl", "file://"+photoSavedFile7.getPath());
    								startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
    							}
    						});
		           		 	Util.saveMyBitmap(tmpbitmap,photoSavedName7,getApplicationContext());
    		        		picIdx++;
    					}
    				}
    			}
    		}else if(picIdx==7){
    			if(photoSavedFile8!=null && photoSavedFile8.exists()){
        			hasPhotoUpload = true;
        			Bitmap bitmap = Util.getBitmap(getApplicationContext(),photoSavedFile8.getPath(),200);
        			addPicImage8.setImageBitmap(bitmap);
        			addPicImage8.setVisibility(View.VISIBLE);
        			addPicImage8.setOnClickListener(new View.OnClickListener() {
						@Override
						public void onClick(View arg0) {
							Bundle bundle = new Bundle();
							bundle.putString("imgUrl", "file://"+photoSavedFile8.getPath());
							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
						}
					});
           		 	Util.saveMyBitmap(bitmap,photoSavedName8,getApplicationContext());
           		 	picIdx++;
    			}else if(data!=null){
    				Bundle bundle = data.getExtras();
    				if(bundle!=null){
    					Bitmap tmpbitmap = (Bitmap)bundle.get("data");
    					if(tmpbitmap!=null){
    						hasPhotoUpload = true;
    						addPicImage8.setImageBitmap(tmpbitmap);
    						addPicImage8.setVisibility(View.VISIBLE);
    						addPicImage8.setOnClickListener(new View.OnClickListener() {
    							@Override
    							public void onClick(View arg0) {
    								Bundle bundle = new Bundle();
    								bundle.putString("imgUrl", "file://"+photoSavedFile8.getPath());
    								startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
    							}
    						});
		           		 	Util.saveMyBitmap(tmpbitmap,photoSavedName8,getApplicationContext());
    		        		picIdx++;
    					}
    				}
    			}
    		}else if(picIdx==8){
    			if(photoSavedFile9!=null && photoSavedFile9.exists()){
        			hasPhotoUpload = true;
        			Bitmap bitmap = Util.getBitmap(getApplicationContext(),photoSavedFile9.getPath(),200);
        			addPicImage9.setImageBitmap(bitmap);
        			addPicImage9.setVisibility(View.VISIBLE);
        			addPicImage9.setOnClickListener(new View.OnClickListener() {
						@Override
						public void onClick(View arg0) {
							Bundle bundle = new Bundle();
							bundle.putString("imgUrl", "file://"+photoSavedFile9.getPath());
							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
						}
					});
           		 	Util.saveMyBitmap(bitmap,photoSavedName9,getApplicationContext());
           		 	picIdx++;
    			}else if(data!=null){
    				Bundle bundle = data.getExtras();
    				if(bundle!=null){
    					Bitmap tmpbitmap = (Bitmap)bundle.get("data");
    					if(tmpbitmap!=null){
    						hasPhotoUpload = true;
    						addPicImage9.setImageBitmap(tmpbitmap);
    						addPicImage9.setVisibility(View.VISIBLE);
    						addPicImage9.setOnClickListener(new View.OnClickListener() {
    							@Override
    							public void onClick(View arg0) {
    								Bundle bundle = new Bundle();
    								bundle.putString("imgUrl", "file://"+photoSavedFile9.getPath());
    								startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
    							}
    						});
		           		 	Util.saveMyBitmap(tmpbitmap,photoSavedName9,getApplicationContext());
    		        		picIdx++;
    					}
    				}
    			}
    		}
   	 	}else if(requestCode==2){
	   	 	if(data!=null){
	   		 	Uri selectedImage = data.getData();
		        String[] filePathColumn = {MediaStore.Images.Media.DATA};
		        Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
		        cursor.moveToFirst();
		        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
		        String picturePath = cursor.getString(columnIndex);
		        cursor.close();
		        if(!TextUtils.isEmpty(picturePath)){
		        	 File userLogoFile = new File(picturePath);  
		        	 if(userLogoFile.exists()){
		        		 hasPhotoUpload = true;
		        		 Bitmap bitmap = Util.getBitmap(getApplicationContext(),picturePath,200);
		        		 if(picIdx==0){
		        			 addPicImage1.setImageBitmap(bitmap);
		        			 addPicImage1.setVisibility(View.VISIBLE);
		        			 addPicImage1.setOnClickListener(new View.OnClickListener() {
		 						@Override
		 						public void onClick(View arg0) {
		 							Bundle bundle = new Bundle();
		 							bundle.putString("imgUrl", "file://"+photoSavedFile1.getPath());
		 							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
		 						}
		 					});
			        		 Util.saveMyBitmap(bitmap,photoSavedName1,getApplicationContext());
			        		 picIdx++;
		        		 }else if(picIdx==1){
		        			 addPicImage2.setImageBitmap(bitmap);
		        			 addPicImage2.setVisibility(View.VISIBLE);
		        			 addPicImage2.setOnClickListener(new View.OnClickListener() {
		 						@Override
		 						public void onClick(View arg0) {
		 							Bundle bundle = new Bundle();
		 							bundle.putString("imgUrl", "file://"+photoSavedFile2.getPath());
		 							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
		 						}
		 					});
			        		 Util.saveMyBitmap(bitmap,photoSavedName2,getApplicationContext());
			        		 picIdx++;
		        		 }else if(picIdx==2){
		        			 addPicImage3.setImageBitmap(bitmap);
		        			 addPicImage3.setVisibility(View.VISIBLE);
		        			 addPicImage3.setOnClickListener(new View.OnClickListener() {
		 						@Override
		 						public void onClick(View arg0) {
		 							Bundle bundle = new Bundle();
		 							bundle.putString("imgUrl", "file://"+photoSavedFile3.getPath());
		 							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
		 						}
		 					});
			        		 Util.saveMyBitmap(bitmap,photoSavedName3,getApplicationContext());
			        		 picIdx++;
		        		 }else if(picIdx==3){
		        			 addPicImage4.setImageBitmap(bitmap);
		        			 addPicImage4.setVisibility(View.VISIBLE);
		        			 addPicImage4.setOnClickListener(new View.OnClickListener() {
		 						@Override
		 						public void onClick(View arg0) {
		 							Bundle bundle = new Bundle();
		 							bundle.putString("imgUrl", "file://"+photoSavedFile4.getPath());
		 							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
		 						}
		 					});
			        		 Util.saveMyBitmap(bitmap,photoSavedName4,getApplicationContext());
			        		 picIdx++;
		        		 }else if(picIdx==4){
		        			 addPicImage5.setImageBitmap(bitmap);
		        			 addPicImage5.setVisibility(View.VISIBLE);
		        			 addPicImage5.setOnClickListener(new View.OnClickListener() {
		 						@Override
		 						public void onClick(View arg0) {
		 							Bundle bundle = new Bundle();
		 							bundle.putString("imgUrl", "file://"+photoSavedFile5.getPath());
		 							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
		 						}
		 					});
			        		 Util.saveMyBitmap(bitmap,photoSavedName5,getApplicationContext());
			        		 picIdx++;
		        		 }else if(picIdx==5){
		        			 addPicImage6.setImageBitmap(bitmap);
		        			 addPicImage6.setVisibility(View.VISIBLE);
		        			 addPicImage6.setOnClickListener(new View.OnClickListener() {
		 						@Override
		 						public void onClick(View arg0) {
		 							Bundle bundle = new Bundle();
		 							bundle.putString("imgUrl", "file://"+photoSavedFile6.getPath());
		 							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
		 						}
		 					});
			        		 Util.saveMyBitmap(bitmap,photoSavedName6,getApplicationContext());
			        		 picIdx++;
		        		 }else if(picIdx==6){
		        			 addPicImage7.setImageBitmap(bitmap);
		        			 addPicImage7.setVisibility(View.VISIBLE);
		        			 addPicImage7.setOnClickListener(new View.OnClickListener() {
		 						@Override
		 						public void onClick(View arg0) {
		 							Bundle bundle = new Bundle();
		 							bundle.putString("imgUrl", "file://"+photoSavedFile7.getPath());
		 							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
		 						}
		 					});
			        		 Util.saveMyBitmap(bitmap,photoSavedName7,getApplicationContext());
			        		 picIdx++;
		        		 }else if(picIdx==7){
		        			 addPicImage8.setImageBitmap(bitmap);
		        			 addPicImage8.setVisibility(View.VISIBLE);
		        			 addPicImage8.setOnClickListener(new View.OnClickListener() {
		 						@Override
		 						public void onClick(View arg0) {
		 							Bundle bundle = new Bundle();
		 							bundle.putString("imgUrl", "file://"+photoSavedFile8.getPath());
		 							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
		 						}
		 					});
			        		 Util.saveMyBitmap(bitmap,photoSavedName8,getApplicationContext());
			        		 picIdx++;
		        		 }else if(picIdx==8){
		        			 addPicImage9.setImageBitmap(bitmap);
		        			 addPicImage9.setVisibility(View.VISIBLE);
		        			 addPicImage9.setOnClickListener(new View.OnClickListener() {
		 						@Override
		 						public void onClick(View arg0) {
		 							Bundle bundle = new Bundle();
		 							bundle.putString("imgUrl", "file://"+photoSavedFile9.getPath());
		 							startActivity(new Intent(getApplicationContext(),GalleryUrlActivity.class).putExtras(bundle));
		 						}
		 					});
			        		 Util.saveMyBitmap(bitmap,photoSavedName9,getApplicationContext());
			        		 picIdx++;
		        		 }
		        	 }
		         }
	   	 	}
   	 	}
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_create_liuxuequan);
		
		init();
	}
	
	private void init(){
		contentEdit = (EditText)findViewById(R.id.add_question_edit);
		addPicImage1 = (ImageView)findViewById(R.id.btn_add_pic_1);
		addPicImage2 = (ImageView)findViewById(R.id.btn_add_pic_2);
		addPicImage3 = (ImageView)findViewById(R.id.btn_add_pic_3);
		addPicImage4 = (ImageView)findViewById(R.id.btn_add_pic_4);
		addPicImage5 = (ImageView)findViewById(R.id.btn_add_pic_5);
		addPicImage6 = (ImageView)findViewById(R.id.btn_add_pic_6);
		addPicImage7 = (ImageView)findViewById(R.id.btn_add_pic_7);
		addPicImage8 = (ImageView)findViewById(R.id.btn_add_pic_8);
		addPicImage9 = (ImageView)findViewById(R.id.btn_add_pic_9);
		maxQuestionText = (TextView)findViewById(R.id.add_question_max_num_text);
		
		findViewById(R.id.btn_back).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		
		contentEdit.addTextChangedListener(new TextWatcher(){
			@Override
			public void afterTextChanged(Editable arg0) {
				// TODO Auto-generated method stub
				maxQuestionText.setText("你还可以输入"+(1000-contentEdit.getText().toString().length())+"字");
			}

			@Override
			public void beforeTextChanged(CharSequence arg0, int arg1,
					int arg2, int arg3) {
			}

			@Override
			public void onTextChanged(CharSequence arg0, int arg1, int arg2,
					int arg3) {
			}});
		
		findViewById(R.id.btn_top_right).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				String content = contentEdit.getText().toString().trim().replace("\n", "");
				if(content.length()<=0){
					if(!hasPhotoUpload){
						Toast.makeText(getApplicationContext(), "请填写具体内容或添加图片", Toast.LENGTH_LONG).show();
						return;
					}
				}
				if(isUploading){
					Toast.makeText(getApplicationContext(), "正在请求中，请勿重复提交", Toast.LENGTH_LONG).show();
					return;
				}
				RequestParams params = new RequestParams();
				params.put("uId", BaseActivity.getMyInfo(getApplicationContext()).getuId());
				params.put("content", content);
//				if(liuxuequanRadio.isChecked()){
//					params.put("statu", "0");
//				}else{
					params.put("statu", "1");
//				}
				if(hasPhotoUpload && photoSavedFile1!=null && photoSavedFile1.exists()){
					try {
						params.put("Studyimg1", photoSavedFile1);
					} catch (FileNotFoundException e) {
						e.printStackTrace();
					}
				}
				if(hasPhotoUpload && photoSavedFile2!=null && photoSavedFile2.exists()){
					try {
						params.put("Studyimg2", photoSavedFile2);
					} catch (FileNotFoundException e) {
						e.printStackTrace();
					}
				}
				if(hasPhotoUpload && photoSavedFile3!=null && photoSavedFile3.exists()){
					try {
						params.put("Studyimg3", photoSavedFile3);
					} catch (FileNotFoundException e) {
						e.printStackTrace();
					}
				}
				if(hasPhotoUpload && photoSavedFile4!=null && photoSavedFile4.exists()){
					try {
						params.put("Studyimg4", photoSavedFile4);
					} catch (FileNotFoundException e) {
						e.printStackTrace();
					}
				}
				if(hasPhotoUpload && photoSavedFile5!=null && photoSavedFile5.exists()){
					try {
						params.put("Studyimg5", photoSavedFile5);
					} catch (FileNotFoundException e) {
						e.printStackTrace();
					}
				}
				if(hasPhotoUpload && photoSavedFile6!=null && photoSavedFile6.exists()){
					try {
						params.put("Studyimg6", photoSavedFile6);
					} catch (FileNotFoundException e) {
						e.printStackTrace();
					}
				}
				if(hasPhotoUpload && photoSavedFile7!=null && photoSavedFile7.exists()){
					try {
						params.put("Studyimg7", photoSavedFile7);
					} catch (FileNotFoundException e) {
						e.printStackTrace();
					}
				}
				if(hasPhotoUpload && photoSavedFile8!=null && photoSavedFile8.exists()){
					try {
						params.put("Studyimg8", photoSavedFile8);
					} catch (FileNotFoundException e) {
						e.printStackTrace();
					}
				}
				if(hasPhotoUpload && photoSavedFile9!=null && photoSavedFile9.exists()){
					try {
						params.put("Studyimg9", photoSavedFile9);
					} catch (FileNotFoundException e) {
						e.printStackTrace();
					}
				}
				HttpClient.getInstance().post(Constants.API_ZHIDAO_ADD_STUDY_CIRCLE_URL, params, getHandler());
				isUploading = true;
				Toast.makeText(getApplicationContext(), "发布中", Toast.LENGTH_SHORT).show();
			}
		});
		
		findViewById(R.id.add_question_image_text).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				if(picIdx>8){
					return;
				}
				new AlertDialog.Builder(CreateLiuxuequanActivity.this).setTitle("选择头像")
				.setItems(new String[]{"拍照","相册"}, new DialogInterface.OnClickListener(){
					@Override
					public void onClick(DialogInterface arg0, int arg1) {
						if(arg1==0){
							File rootFile = new File(Constants.IMAGE_PHOTO_TMP_PATH);
							if(!rootFile.exists()){
								rootFile.mkdirs();
							}
							Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
							if(picIdx==0){
								photoSavedName1 = "addQuesPic_1_"+System.currentTimeMillis()+".jpg";
								photoSavedFile1 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName1);
								intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(photoSavedFile1));
							}else if(picIdx==1){
								photoSavedName2 = "addQuesPic_2_"+System.currentTimeMillis()+".jpg";
								photoSavedFile2 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName2);
								intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(photoSavedFile2));
							}else if(picIdx==2){
								photoSavedName3 = "addQuesPic_3_"+System.currentTimeMillis()+".jpg";
								photoSavedFile3 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName3);
								intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(photoSavedFile3));
							}else if(picIdx==3){
								photoSavedName4 = "addQuesPic_4_"+System.currentTimeMillis()+".jpg";
								photoSavedFile4 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName4);
								intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(photoSavedFile4));
							}else if(picIdx==4){
								photoSavedName5 = "addQuesPic_5_"+System.currentTimeMillis()+".jpg";
								photoSavedFile5 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName5);
								intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(photoSavedFile5));
							}else if(picIdx==5){
								photoSavedName6 = "addQuesPic_6_"+System.currentTimeMillis()+".jpg";
								photoSavedFile6 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName6);
								intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(photoSavedFile6));
							}else if(picIdx==6){
								photoSavedName7 = "addQuesPic_7_"+System.currentTimeMillis()+".jpg";
								photoSavedFile7 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName7);
								intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(photoSavedFile7));
							}else if(picIdx==7){
								photoSavedName8 = "addQuesPic_8_"+System.currentTimeMillis()+".jpg";
								photoSavedFile8 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName8);
								intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(photoSavedFile8));
							}else if(picIdx==8){
								photoSavedName9 = "addQuesPic_9_"+System.currentTimeMillis()+".jpg";
								photoSavedFile9 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName9);
								intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(photoSavedFile9));
							}
		                    intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
		                    startActivityForResult(intent, 1);
						}else{
							if(picIdx==0){
								photoSavedName1 = "addQuesPic_1_"+System.currentTimeMillis()+".jpg";
								photoSavedFile1 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName1);
							}else if(picIdx==1){
								photoSavedName2 = "addQuesPic_2_"+System.currentTimeMillis()+".jpg";
								photoSavedFile2 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName2);
							}else if(picIdx==2){
								photoSavedName3 = "addQuesPic_3_"+System.currentTimeMillis()+".jpg";
								photoSavedFile3 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName3);
							}else if(picIdx==3){
								photoSavedName4 = "addQuesPic_4_"+System.currentTimeMillis()+".jpg";
								photoSavedFile4 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName4);
							}else if(picIdx==4){
								photoSavedName5 = "addQuesPic_5_"+System.currentTimeMillis()+".jpg";
								photoSavedFile5 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName5);
							}else if(picIdx==5){
								photoSavedName6 = "addQuesPic_6_"+System.currentTimeMillis()+".jpg";
								photoSavedFile6 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName6);
							}else if(picIdx==6){
								photoSavedName7 = "addQuesPic_7_"+System.currentTimeMillis()+".jpg";
								photoSavedFile7 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName7);
							}else if(picIdx==7){
								photoSavedName8 = "addQuesPic_8_"+System.currentTimeMillis()+".jpg";
								photoSavedFile8 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName8);
							}else if(picIdx==8){
								photoSavedName9 = "addQuesPic_9_"+System.currentTimeMillis()+".jpg";
								photoSavedFile9 = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName9);
							}
							Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
							startActivityForResult(i, 2);
						}
					}})
				.setNegativeButton("取消", null).show();
			}
		});
	}

}
